*** NOTE:  This do-file performs the refinance ARM specfications in Tables 4 and 8. ***



program mymlogit_uh_lf
	version 10.1
	args lnf bxj1 bxj2 loc_j1_l1 loc_j1_l2 mass_point loc_j2_l1 loc_j2_l2
	tempvar denom_l1 denom_l2 mass_prob_l1 mass_prob_l2
	quietly generate double `denom_l1' = 1 + exp(`bxj1' + `loc_j1_l1') + exp(`bxj2' + `loc_j2_l1')
	quietly generate double `denom_l2' = 1 + exp(`bxj1' + `loc_j1_l2') + exp(`bxj2' + `loc_j2_l2')

	quietly generate double `mass_prob_l1' = exp(`mass_point') / (1 + exp(`mass_point'))
	quietly generate double `mass_prob_l2' = 1 / (1 + exp(`mass_point'))


	quietly replace `lnf' = ln((`mass_prob_l1'*(1/`denom_l1')) + (`mass_prob_l2'*(1/`denom_l2'))) if $ML_y1 == 0
	quietly replace `lnf' = ln((`mass_prob_l1'*(exp(`bxj1' + `loc_j1_l1')/`denom_l1')) + (`mass_prob_l2'*(exp(`bxj1' + `loc_j1_l2')/`denom_l2'))) if $ML_y1 == 1
	quietly replace `lnf' = ln((`mass_prob_l1'*(exp(`bxj2' + `loc_j2_l1')/`denom_l1')) + (`mass_prob_l2'*(exp(`bxj2' + `loc_j2_l2')/`denom_l2'))) if $ML_y1 == 2
end



log using "C:\Documents and Settings\morgan.rose\My Documents\Foreclosure\Geographic Consistency\Stata\Stata Logs\20110120 mymlogit_uh_lf all10 -- culled 10 size -- refi_arm.log", replace



*****************
*****************
*** REFI_ARM  ***
*** ALL10     ***
*** 10 size   ***
*****************
*****************

use "C:\Documents and Settings\morgan.rose\My Documents\Foreclosure\Geographic Consistency\Stata\Stata Data\All 10 MSAs\all10 10 size both refi_arm generated.dta", clear

egen big_loan_num = group(loan_id)

keep if outsample_a != 1 & fico > 0 & cltv != 0 & balance != 0
drop loan_id first_rate pp_pen pp_term state mba_stat sch_mnth_p currmonth origmonth mba_stat_lead1 outcome_b outsample_b outcome_c hpa init_rate orig_risk_prem subprime index_id rate_reset term loan_id_num _merge

generate msa_atl = 0
generate msa_bal = 0
generate msa_chi = 0
generate msa_los = 0
generate msa_mia = 0
generate msa_min = 0
generate msa_new = 0
generate msa_pho = 0
generate msa_pit = 0
generate msa_san = 0
replace msa_atl = 1 if msa_num == 1
replace msa_bal = 1 if msa_num == 2
replace msa_chi = 1 if msa_num == 3
replace msa_los = 1 if msa_num == 4
replace msa_mia = 1 if msa_num == 5
replace msa_min = 1 if msa_num == 6
replace msa_new = 1 if msa_num == 7
replace msa_pho = 1 if msa_num == 8
replace msa_pit = 1 if msa_num == 9
replace msa_san = 1 if msa_num == 10
compress

generate pre_atl = prepay_pen * msa_atl
generate pre_bal = prepay_pen * msa_bal
generate pre_chi = prepay_pen * msa_chi
generate pre_los = prepay_pen * msa_los
generate pre_mia = prepay_pen * msa_mia
generate pre_min = prepay_pen * msa_min
generate pre_new = prepay_pen * msa_new
generate pre_pho = prepay_pen * msa_pho
generate pre_pit = prepay_pen * msa_pit
generate pre_san = prepay_pen * msa_san
compress

generate pre_end_atl = prepay_pen_end * msa_atl
generate pre_end_bal = prepay_pen_end * msa_bal
generate pre_end_chi = prepay_pen_end * msa_chi
generate pre_end_los = prepay_pen_end * msa_los
generate pre_end_mia = prepay_pen_end * msa_mia
generate pre_end_min = prepay_pen_end * msa_min
generate pre_end_new = prepay_pen_end * msa_new
generate pre_end_pho = prepay_pen_end * msa_pho
generate pre_end_pit = prepay_pen_end * msa_pit
generate pre_end_san = prepay_pen_end * msa_san
compress

generate doc_atl = lownodoc * msa_atl
generate doc_bal = lownodoc * msa_bal
generate doc_chi = lownodoc * msa_chi
generate doc_los = lownodoc * msa_los
generate doc_mia = lownodoc * msa_mia
generate doc_min = lownodoc * msa_min
generate doc_new = lownodoc * msa_new
generate doc_pho = lownodoc * msa_pho
generate doc_pit = lownodoc * msa_pit
generate doc_san = lownodoc * msa_san
compress

************************************
*** WITHOUT MSA-PLP interactions ***
************************************

*** Generating matrix of starting values using mlogit ***
mlogit outcome_a prepay_pen prepay_pen_end lownodoc cashout fico cltv payment_adj2 adj_1st post_adj_1st spread ageofloan ageofloan_2 rel_loan_size chg_unempl var_hpi var_6molibor vint2003 vint2004 vint2005 vint2006 judicial msa_atl msa_bal msa_chi msa_mia msa_min msa_new msa_pho msa_pit msa_san if outsample_a != 1 & fico > 0 & cltv != 0 & balance != 0, cluster(big_loan_num)
outreg2 using "C:\Documents and Settings\morgan.rose\My Documents\Foreclosure\Geographic consistency\Stata\Stata Outregs\20110120 mlogit all10 culled 10 size.txt", append onecol text bracket(se) e(all)
do "C:\Documents and Settings\morgan.rose\My Documents\Foreclosure\Geographic Consistency\Stata\Stata Do-files\mymlogit_uh_lf\creating starter matrix for mymlogit_uh_lf.do"

*** Running mymlogit_uh_lf ***
*** NOTE: Table 4, refinance ARMs ***
ml model lf mymlogit_uh_lf (default: outcome_a = prepay_pen prepay_pen_end lownodoc cashout fico cltv payment_adj2 adj_1st post_adj_1st spread ageofloan ageofloan_2 rel_loan_size chg_unempl var_hpi var_6molibor vint2003 vint2004 vint2005 vint2006 judicial msa_atl msa_bal msa_chi msa_mia msa_min msa_new msa_pho msa_pit msa_san, noconstant) (payoff: prepay_pen prepay_pen_end lownodoc cashout fico cltv payment_adj2 adj_1st post_adj_1st spread ageofloan ageofloan_2 rel_loan_size chg_unempl var_hpi var_6molibor vint2003 vint2004 vint2005 vint2006 judicial msa_atl msa_bal msa_chi msa_mia msa_min msa_new msa_pho msa_pit msa_san, noconstant) (default_const1:) (default_const2:) (prob_coeff1:) (payoff_const1:) (payoff_const2:) if outsample_a != 1 & fico > 0 & cltv != 0 & balance != 0, cluster(big_loan_num)
*ml check
ml init starter, copy
ml maximize, iterate(1000) difficult
outreg2 using "C:\Documents and Settings\morgan.rose\My Documents\Foreclosure\Geographic consistency\Stata\Stata Outregs\20110120 mymlogit_uh_lf all10 culled 10 size.txt", append onecol text bracket(se) e(all)
*ml graph

*********************************
*** WITH MSA-PLP interactions ***
*********************************

*** Generating matrix of starting values using mlogit ***
mlogit outcome_a prepay_pen prepay_pen_end lownodoc cashout fico cltv payment_adj2 adj_1st post_adj_1st spread ageofloan ageofloan_2 rel_loan_size chg_unempl var_hpi var_6molibor vint2003 vint2004 vint2005 vint2006 judicial msa_atl msa_bal msa_chi msa_mia msa_min msa_new msa_pho msa_pit msa_san pre_atl pre_bal pre_chi pre_mia pre_min pre_new pre_pho pre_pit pre_san pre_end_atl pre_end_bal pre_end_chi pre_end_mia pre_end_min pre_end_new pre_end_pho pre_end_pit pre_end_san doc_atl doc_bal doc_chi doc_mia doc_min doc_new doc_pho doc_pit doc_san if outsample_a != 1 & fico > 0 & cltv != 0 & balance != 0, cluster(big_loan_num)
outreg2 using "C:\Documents and Settings\morgan.rose\My Documents\Foreclosure\Geographic consistency\Stata\Stata Outregs\20110120 mlogit all10 culled 10 size.txt", append onecol text bracket(se) e(all)
do "C:\Documents and Settings\morgan.rose\My Documents\Foreclosure\Geographic Consistency\Stata\Stata Do-files\mymlogit_uh_lf\creating starter matrix for mymlogit_uh_lf.do"

*** Running mymlogit_uh_lf ***
*** NOTE: Table 8, refinance ARMs ***
ml model lf mymlogit_uh_lf (default: outcome_a = prepay_pen prepay_pen_end lownodoc cashout fico cltv payment_adj2 adj_1st post_adj_1st spread ageofloan ageofloan_2 rel_loan_size chg_unempl var_hpi var_6molibor vint2003 vint2004 vint2005 vint2006 judicial msa_atl msa_bal msa_chi msa_mia msa_min msa_new msa_pho msa_pit msa_san pre_atl pre_bal pre_chi pre_mia pre_min pre_new pre_pho pre_pit pre_san pre_end_atl pre_end_bal pre_end_chi pre_end_mia pre_end_min pre_end_new pre_end_pho pre_end_pit pre_end_san doc_atl doc_bal doc_chi doc_mia doc_min doc_new doc_pho doc_pit doc_san, noconstant) (payoff: prepay_pen prepay_pen_end lownodoc cashout fico cltv payment_adj2 adj_1st post_adj_1st spread ageofloan ageofloan_2 rel_loan_size chg_unempl var_hpi var_6molibor vint2003 vint2004 vint2005 vint2006 judicial msa_atl msa_bal msa_chi msa_mia msa_min msa_new msa_pho msa_pit msa_san pre_atl pre_bal pre_chi pre_mia pre_min pre_new pre_pho pre_pit pre_san pre_end_atl pre_end_bal pre_end_chi pre_end_mia pre_end_min pre_end_new pre_end_pho pre_end_pit pre_end_san doc_atl doc_bal doc_chi doc_mia doc_min doc_new doc_pho doc_pit doc_san, noconstant) (default_const1:) (default_const2:) (prob_coeff1:) (payoff_const1:) (payoff_const2:) if outsample_a != 1 & fico > 0 & cltv != 0 & balance != 0, cluster(big_loan_num)
*ml check
ml init starter, copy
ml maximize, iterate(1000) difficult
outreg2 using "C:\Documents and Settings\morgan.rose\My Documents\Foreclosure\Geographic consistency\Stata\Stata Outregs\20110120 mymlogit_uh_lf all10 culled 10 size.txt", append onecol text bracket(se) e(all)
*ml graph
do "C:\Documents and Settings\morgan.rose\My Documents\Foreclosure\Geographic Consistency\Stata\Stata Do-files\mymlogit_uh_lf\Wald tests -- MSA-PLP interactions -- ARMs.do"



log close



program drop mymlogit_uh_lf



clear



